//package com.ljx.itbbs.server.mq.config;
//
//import com.ljx.itbbs.server.mall.consumer.CouponConsumer;
//import com.ljx.itbbs.server.mall.consumer.OrderExpireConsumer;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.*;
//import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
//import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
//import org.springframework.amqp.rabbit.connection.CorrelationData;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
//import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @Author: LiJunXi
// * @Description: RabbitMQ消息队列配置类
// * @Date: 2024-03-30  22:36
// */
//@Slf4j
////@Configuration
//public class RabbitMQConfig {
//
//    public final static String EXCHANGE = "itbbs.topic";
//    public final static String COUPON_QUEUE = "itbbs.coupon";
//
//
////    /**
////     * channel链接工厂
////     */
////    @Autowired
////    private CachingConnectionFactory connectionFactory;
////
////    /**
////     * 监听器容器配置
////     */
////    @Autowired
////    private SimpleRabbitListenerContainerFactoryConfigurer factoryConfigurer;
//
////    @Bean
////    public TopicExchange exchange() {
////        //设置为持久化 不自动删除
////        return new TopicExchange(RabbitMQConfig.EXCHANGE, true, false);
////    }
////
////    @Bean("couponQueue")
////    public Queue couponQueue() {
////        return new Queue(RabbitMQConfig.COUPON_QUEUE, true);
////    }
////
////    @Bean
////    Binding bindingCouponExchange() {
////        return BindingBuilder.bind(couponQueue()).to(exchange()).with(RabbitMQConfig.COUPON_QUEUE);
////    }
//
////    /**
////     * 声明RabbitTemplate
////     * @return
////     */
////    @Bean
////    public RabbitTemplate rabbitTemplate(){
////        //消息发送成功确认，对应application.properties中的spring.rabbitmq.publisher-confirms=true
////        connectionFactory.setPublisherConfirms(true);
////        //消息发送失败确认，对应application.properties中的spring.rabbitmq.publisher-returns=true
////        connectionFactory.setPublisherReturns(true);
////        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
////        //设置消息发送格式为json
////        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
////        rabbitTemplate.setMandatory(true);
////        // 消息发送到exchange回调 需设置：spring.rabbitmq.publisher-confirms=true
////        rabbitTemplate.setConfirmCallback(new RabbitTemplate.ConfirmCallback() {
////            @Override
////            public void confirm(CorrelationData correlationData, boolean ack, String cause) {
////                log.info("消息发送成功:correlationData({}),ack({}),cause({})",correlationData,ack,cause);
////            }
////        });
////        // 消息从exchange发送到queue失败回调  需设置：spring.rabbitmq.publisher-returns=true
////        rabbitTemplate.setReturnCallback(new RabbitTemplate.ReturnCallback() {
////            @Override
////            public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
////                log.info("消息丢失:exchange({}),route({}),replyCode({}),replyText({}),message:{}",exchange,routingKey,replyCode,replyText,message);
////            }
////        });
////        return rabbitTemplate;
////    }
//
////    /**
////     * 注入优惠券对列消费监听器
////     */
////    @Autowired
////    private CouponConsumer couponConsumer;
////
////
////    /**
////     * 声明优惠券列监听器配置容器
////     * @return
////     */
////    @Bean("couponConsumerContainer")
////    public SimpleMessageListenerContainer couponConsumerContainer(){
////        //创建监听器容器工厂
////        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
////        //将配置信息和链接信息赋给容器工厂
////        factoryConfigurer.configure(factory,connectionFactory);
////        //容器工厂创建监听器容器
////        SimpleMessageListenerContainer container = factory.createListenerContainer();
////        //指定监听器
////        container.setMessageListener(couponConsumer);
////        //指定监听器监听的队列
////        container.setQueues(couponQueue());
////        return container;
////    }
//
//    //===============================================订单超时死信队列=====================================================
//    private final static String DEAD_ORDER_EXCHANGE = "DeadOrderExchange";
//    private final static String DEAD_ORDER_QUEUE = "itbbs.deadOrderQueue";
//    private final static String ORDER_EXCHANGE = "OrderExchange";
//    public final static String ORDER_QUEUE = "itbbs.order";
////
////    private final static int DEAD_ORDER_EXPIRE_TIME = 15000 * 60;
////
////    @Bean
////    public Queue orderQueue(){
////        Map<String, Object> args = new HashMap<>(2);
////        // 绑定我们的死信交换机
////        args.put("x-dead-letter-exchange", DEAD_ORDER_EXCHANGE);
////        // 绑定我们的路由key
////        args.put("x-dead-letter-routing-key", DEAD_ORDER_QUEUE);
////        // 声明队列的TTL
////        args.put("x-message-ttl", DEAD_ORDER_EXPIRE_TIME);
////        return new Queue(ORDER_QUEUE, true, false, false, args);
////    }
////
////    //绑定死信队列
////    @Bean
////    public Queue dlxQueue() {
////        return new Queue(DEAD_ORDER_QUEUE);
////    }
////    //绑定死信交换机
////    @Bean
////    public DirectExchange dlxExchange() {
////        return new DirectExchange(DEAD_ORDER_EXCHANGE);
////    }
////
////    @Bean
////    public DirectExchange orderExchange(){
////        return new DirectExchange(ORDER_EXCHANGE);
////    }
////
////    @Bean
////    public Binding orderBindingExchange() {
////        return BindingBuilder.bind(orderQueue()).to(orderExchange()).with(ORDER_QUEUE);
////    }
////
////    @Bean
////    public Binding deadBindingExchange() {
////        return BindingBuilder.bind(dlxQueue()).to(dlxExchange()).with(DEAD_ORDER_QUEUE);
////    }
////
////    /**
////     * 注入订单监听器
////     */
////    @Autowired
////    private OrderExpireConsumer orderExpireConsumer;
////
////    /**
////     * 订单队列监听器容器
////     * @return
////     */
////    @Bean
////    public SimpleMessageListenerContainer orderExpireConsumerContainer(){
////        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
////        factoryConfigurer.configure(factory,connectionFactory);
////        SimpleMessageListenerContainer listenerContainer = factory.createListenerContainer();
////        listenerContainer.setMessageListener(orderExpireConsumer);
////        listenerContainer.setQueues(dlxQueue());
////        return listenerContainer;
////    }
////
//
//
//}
